<template>
  <div class="app-container">

    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="用户ID:">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户账号:">
        <el-input
          v-model="queryParams.userAccount"
          placeholder="请输入用户账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品ID:">
        <el-input
          v-model="queryParams.goodsId"
          placeholder="请输入商品ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品名称:">
        <el-input
          v-model="queryParams.goodsName"
          placeholder="请输入商品名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="商品状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择商品状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="goodsList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="用户ID" align="center" prop="userId"/>
      <el-table-column label="用户账号" align="center" prop="userAccount"/>
      <el-table-column label="商品ID" align="center" prop="goodsId"/>
      <el-table-column label="商品信息" align="center" width="400px">
        <template slot-scope="scope">
          <el-image
            :src="requestUrl + scope.row.mainImg"
            style="
              width: 140px;
              height: 100px;
              float: center;
              display: inline-block;
            "
          />
          <span
            style="
              float: center;
              vertical-align: middle;
              display: inline-block;
              line-height: 100px;
            "
          >{{ scope.row.goodsName }}</span
          >
        </template>
      </el-table-column>
      <el-table-column label="商品编号" align="center" prop="serialNum"/>
      <el-table-column label="初始售价" align="center" prop="originalPrice"/>
      <el-table-column label="当前售价" align="center" prop="currentPrice"/>
      <el-table-column label="商品状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === 0">仓库中</span>
          <span v-if="scope.row.status === 1">转售中</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listResaleGoodsInfo} from "@/api/admin/activityGoodsInfo";

export default {
  name: "activityResaleGoods",
  data() {
    return {
      requestUrl: this.$img.requestUrl,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 视频管理表格数据
      goodsList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      statusOptions: [
        {
          value: "0",
          label: "仓库中",
        },
        {
          value: "1",
          label: "转售中",
        },
      ],
    };
  },

  created() {
    this.getList();
  },

  methods: {
    /** 查询商品分类列表 */
    getList() {
      this.loading = true;
      listResaleGoodsInfo(this.queryParams).then((response) => {
        this.goodsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 搜索按钮操作 */
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  },
};
</script>
